﻿using UnityEngine;
using System.Collections;

public class GameCamera : MonoBehaviour {

	
	//http://www.youtube.com/watch?v=pSN2x3dPgYw&list=PLQSzy9LlXwas-6uXiU5rCoYc0mHUWykpJ&index=6
	//umbes 20.00 alates loob selle
	// Use this for initialization

	private Vector3 cameraTarget;

	private float scrollSensitivity = 7.0f;
	private float scrollMaxHeight = 30.0f;
	private float scrollMinHeight = 10.0f;

	private Transform target;

	void Start () {
		target = GameObject.FindGameObjectWithTag ("Player").transform;
	}
	
	// Update is called once per frame
	void Update () {
		cameraTarget = new Vector3 (target.position.x, transform.position.y, target.position.z);
		if (Input.GetAxis ("Mouse ScrollWheel") != 0) {
			transform.Translate (scrollSensitivity * Vector3.forward * Input.GetAxis ("Mouse ScrollWheel"));
		}
		if (transform.position.y < scrollMinHeight) {
			Vector3 temp = transform.position;
			temp.y = scrollMinHeight;
			transform.position = temp;
		}
		if (transform.position.y > scrollMaxHeight) {
			Vector3 temp = transform.position;
			temp.y = scrollMaxHeight;
			transform.position = temp;
		}
	}

	void FixedUpdate(){
			transform.position = Vector3.Lerp (transform.position, cameraTarget, Time.deltaTime * 8);
		}
	
}
